package com.example.ywj.toutiao;

import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.example.ywj.toutiao.utils.SpUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IndexActivity extends AppCompatActivity {
    private static final String TAG = "IndexActivity";
    @BindView(R.id.imageView_index)
    public ImageView im_index;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        ButterKnife.bind(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//因为不是所有的系统都可以设置颜色的，在4.4以下就不可以。。有的说4.1，所以在设置的时候要检查一下系统版本是否是4.1以上
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.trgray));
        }
        Integer arr[] = {R.drawable.r2,R.drawable.r3,R.drawable.r4,R.drawable.r11};
        int index = (int)(0+Math.random()*(3-0+1));
        im_index.setImageResource(arr[index]);
       new Thread(){
           @Override
           public void run() {
               try {
                   Thread.sleep(1500);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               Message msg = Message.obtain();
               //  发送给主线程的标记
               msg.what = 0;
               handler.sendMessage(msg);
           }
       }.start();
    }
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
           switch (msg.what){
               case 0:
                   SpUtils.putBoolean(IndexActivity.this,"isreturn",false);
                   Intent intent1 = new Intent(IndexActivity.this,MainActivity.class);
                   startActivity(intent1);
                   finish();
                   break;
           }
        }
    };
}
